﻿using System.Collections.Generic;
using BrnMall.Manager.Domain.WeApp;

namespace BrnMall.Manager.Manager.WeApp
{
    /// <summary>
    /// 小程序表单ID管理
    /// </summary>
    public static class WeAppFormIDManager
    {
        public static void Add(WeAppFormID formId)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(formId);
            }
        }

        public static void Delete(int id)
        {
            using (var db = new QDMallDatabase())
            {
                db.Delete<WeAppFormID>(id);
            }
        }
        public static void BatchDelete(IList<int> ids)
        {
            using (var db = new QDMallDatabase())
            {
                db.BeginTransaction();
                foreach (var id in ids)
                {
                    db.Delete<WeAppFormID>(id);
                }
                db.CompleteTransaction();
            }
        }
        public static WeAppFormID GetFormIdByUid(int uid)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<WeAppFormID>("select top 1 * from wechat_weappformid where uid=@0 order by expiresin", uid);
            }
        }
        public static WeAppFormID GetFormIdByOpenId(string openId)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<WeAppFormID>("select top 1 * from wechat_weappformid where openid=@0 order by expiresin", openId);
            }
        }
    }
}
